<%--
  Created by IntelliJ IDEA.
  User: gem-inno
  Date: 2018/9/21
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <head>
        <title>ajax演示</title>
        <script type="text/javascript" src="js/jquery-3.2.1.js"></script>
    </head>
    <body>
        <input type="button" value="请求" onclick="requestAjax()">
        <input type="button" value="请求2" onclick="requestAjax2()">
    </body>
    <script type="text/javascript">
        //var contextPath = "${pageContext.servletContext.contextPath}";
        function requestAjax() {
            //$.get(url,data,function(){}, dataType)
            //$.get("/ajax/helloAjax");

            //有回调函数
           /* $.get("/ajax/helloAjax",function (msg) {
                alert(msg);
            })*/

           //传递参数
            $.get("/ajax/helloAjax",{"name":"jack","age":25},function (msg) {
                alert(msg);
            })
        }

        function requestAjax2() {
            $.ajax({
                url:"/ajax/helloAjax",
                data: {"name":"jack","age":25},
                type: "post",//请求方式
                success: function (msg) {
                    //将字符串转对象
                    var obj = JSON.parse(msg);
                    alert(obj.id);
                }
            })
        }

    </script>
</html>
